package Demo5;


class Singleton{
    private static Singleton instance=new Singleton();

    public static Singleton getInstance(){
        return instance;
    }
    private Singleton() {
    }
}

class Singleton2{

private static Singleton2 instance ;

static {
    instance=new Singleton2();
}

//对外提供方法获取该对象
public static Singleton2 getInstance(){
    return instance;
}

    //私有化的构造方法
    public Singleton2() {
    }
}

public class Main8 {
    public static void main(String[] args) {
        Singleton instance1=Singleton.getInstance();
        Singleton instance2=Singleton.getInstance();
        System.out.println(instance2==instance1);
    }
}
